/***********************************************************************************
@file   
@author
@attention
@index   led_control(status);	
***********************************************************************************/
#include "led.h"
/***********************************************************************************
 * @para
***********************************************************************************/
uint32_t led_opa_cnt;    //操作计数
uint32_t led_opa_flag;
/***********************************************************************************
 * @brief  
***********************************************************************************/
void led_ctrl_all(uint8_t sta)			
{
	switch(sta)
	{
		case 1:  led_green(1); led_yellow(1); led_red1(1); led_red2(1); break;         
        case 0:  led_green(0); led_yellow(0); led_red1(0); led_red2(0); break;
		default:break;		 
	}
}
/***********************************************************************************
 * @brief  控制背光和红绿黄三个指示灯,根据传感器状态显LED
 * @retval status
***********************************************************************************/
void led_control(uint8_t sta)			
{
	switch(sta)
	{
		case 0:  
                 if(infrared_en_read&&sleep_obj.tim_cnt>21)
                 {
                    if(led_opa_flag)
                    {
                        led_green(1); led_yellow(0); led_red1(0); led_red2(0);
                    }   
                    else
                    {
                        led_green(0); led_yellow(0); led_red1(0); led_red2(0);
                    }
                 }                

        break;         
		case 1:
        case 6:  led_green(0); led_yellow(0); led_red1(1); led_red2(0); break;
		case 2:  led_green(0); led_yellow(0); led_red1(0); led_red2(1); break;
		case 3:  led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;
		case 4:  led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;
		case 5:  led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;
		case 7:  led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;
		default: led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;//led_yellow(1);	 
	}
}
/***********************************************************************************
 * @brief  预热闪烁
***********************************************************************************/
void led_flicker(void)
{
    static uint16_t led_shine=0;
    
    if(led_shine%100==0)
    {
        led_ctrl_all(1);
    }
    else if(led_shine%50==0) 
    {
        led_ctrl_all(0);
    }
    led_shine++;
}
/***********************************************************************************
 * @brief 
***********************************************************************************/
void led_check_timer(void)
{ 
    led_opa_cnt++;
    if(led_opa_cnt<20)  led_opa_flag=0;        
    if(led_opa_cnt>20)  led_opa_flag=1;    
    if(led_opa_cnt>40) 
    {
        led_opa_flag = 0; 
        led_opa_cnt  = 0;
    }      
}
/***********************************************************************************
 * @brief 用于led睡眠前同步状态防止睡眠后绿灯熄灭
***********************************************************************************/
void led_syn_status(uint8_t sta)
{
	switch(sta)
	{
		case 0:  led_green(1); led_yellow(0); led_red1(0); led_red2(0);break; 
		case 1:
        case 6:  led_green(0); led_yellow(0); led_red1(1); led_red2(0); break;
		case 2:  led_green(0); led_yellow(0); led_red1(0); led_red2(1); break;
		case 3:  led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;
		case 4:  led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;
		case 5:  led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;
		case 7:  led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;
		default: led_green(0); led_yellow(1); led_red1(0); led_red2(0); break;//led_yellow(1);	 
	}
}
